package cn.bb.action;

import cn.bb.pojo.Page;
import cn.bb.pojo.User;
import cn.bb.service.IUserService;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import org.springframework.beans.factory.annotation.Autowired;


import java.util.HashMap;
import java.util.Map;

public class UserAction extends ActionSupport implements ModelDriven<Object> {
    private User user;
    private Integer currentPage;
    private Integer pageSize;
    @Autowired
    private IUserService userService;
    private Page page;
    public String getCond(){//获得用户的信息
        Map<String,Object> map = new HashMap<>();
        map.put("currentPage",currentPage);
        map.put("pageSize",pageSize);
        map.put("user",user);
        page = userService.queryLikeUsers(map);
        //System.out.println(page);
        return SUCCESS;
    }

    /**
     * 增加用户
     * @return
     */
    public String addUser(){
        System.out.println(user);
        userService.addUsers(user);
        return SUCCESS;
    }

    /**
     * 查看用户的具体信息
     * @return
     */
    public String detailOneUser(){
        System.out.println(user);
        User u = userService.UserDetail(user);
        ActionContext.getContext().put("data",u);
        return SUCCESS;
    }

    /**
     * 修改用户信息
     * @return
     */
    public String updateUser(){
        System.out.println(user);
        userService.updateUsers(user);
        return SUCCESS;
    }
    public String delUser(){
        userService.deleteDao(user);
        return SUCCESS;
    }
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        this.currentPage = currentPage;
    }

    public IUserService getUserService() {
        return userService;
    }

    public void setUserService(IUserService userService) {
        this.userService = userService;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    @Override
    public User getModel() {
        if(user == null){
            user = new User();
        }
        return user;
    }
}
